using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web.Mvc;

namespace Uber.WebUI.Controllers
{
    public class BuyController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult License()
        {
            return View();
        }

        //[HttpPost]
        //public ActionResult BuyAwf()
        //{
        //    return Content(HttpPost("http://sites.fastspring.com/awesomec/api/order", "product_1_path=/aspnetprojectawesomejqueryajaxcontrols&product_1_quantity=3&operation=create&destination=contents"));
        //}

        //public static class Exts
        //{
        //    public static IDictionary<string, string> ToDictionary(this NameValueCollection col)
        //    {
        //        return col.Keys.Cast<object>().ToDictionary(key => (string)key, key => col[(string)key]);
        //    }
        //}


        //private string DoPost(string url, IDictionary<string, string> formVals)
        //{
        //    var req = (HttpWebRequest)WebRequest.Create(url);
        //    req.Method = "POST";
        //    req.ContentType = "application/x-www-form-urlencoded";
        //    var param = Request.BinaryRead(Request.ContentLength);
        //    var strRequest = Encoding.ASCII.GetString(param);

        //    var sb = new StringBuilder();
        //    sb.Append(strRequest);

        //    foreach (var key in formVals.Keys)
        //    {
        //        sb.AppendFormat("&{0}={1}", key, formVals[key]);
        //    }
        //    strRequest += sb.ToString();
        //    req.ContentLength = strRequest.Length;

        //    string response;
        //    using (var streamOut = new StreamWriter(req.GetRequestStream(), Encoding.ASCII))
        //    {
        //        streamOut.Write(strRequest);
        //        streamOut.Close();
        //        using (var streamIn = new StreamReader(req.GetResponse().GetResponseStream()))
        //        {
        //            response = streamIn.ReadToEnd();
        //        }
        //    }
        //    return response;
        //}

        //string HttpPost(string uri, string parameters)
        //{
        //    // parameters: name1=value1&name2=value2	
        //    WebRequest webRequest = WebRequest.Create(uri);
        //    //string ProxyString = 
        //    //   System.Configuration.ConfigurationManager.AppSettings
        //    //   [GetConfigKey("proxy")];
        //    //webRequest.Proxy = new WebProxy (ProxyString, true);
        //    //Commenting out above required change to App.Config
        //    webRequest.ContentType = "application/x-www-form-urlencoded";
        //    webRequest.Method = "POST";
        //    byte[] bytes = Encoding.ASCII.GetBytes(parameters);
        //    Stream os = null;
        //    try
        //    { // send the Post
        //        webRequest.ContentLength = bytes.Length;   //Count bytes to send
        //        os = webRequest.GetRequestStream();
        //        os.Write(bytes, 0, bytes.Length);         //Send it
        //    }
        //    finally
        //    {
        //        if (os != null)
        //        {
        //            os.Close();
        //        }
        //    }

        //    var webResponse = webRequest.GetResponse();
        //    var sr = new StreamReader(webResponse.GetResponseStream());
        //    return sr.ReadToEnd().Trim();

        //}
    }


}